<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    {include file="public/static" /}
    <link rel="stylesheet" href="__components__/eleTree/eleTree.css" media="all">
    <style>
        .ele5{
            width: 90%;
        }
    </style>
</head>
<body>

{include file="public/nav" /}

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body ">
                    <form class="layui-form layui-col-space5" >
                        <div class="layui-inline layui-show-xs-block" style="width: 120px;">
                            <input type="text" name="phone" placeholder="联系方式" autocomplete="off" class="layui-input" value="{$Request.param.phone}" />
                        </div>
                        <div class="layui-inline layui-show-xs-block" style="width: 120px;">
                            <input type="text" name="name" placeholder="姓名" autocomplete="off" class="layui-input" value="{$Request.param.name}"/>
                        </div>
                        <div class="layui-inline" >
                            <input type="hidden" id="roleId" name="roleId" value="{$Request.param.roleId}">
                            <input type="text" readonly name="role" placeholder="选择角色" autocomplete="off" class="layui-input" value="{$Request.param.role}" />
                            <div class="eleTree ele5" lay-filter="data5"></div>
                        </div>
                        <div class="layui-inline" style="width: 100px;">
                            <select lay-filter="province" level="2" name="province" id="province">
                                <option value="0">选择省份</option>
                                {volist name="province" id="vo"}
                                    <option value="{$vo.ci_id}" {eq name="Request.param.province" value="$vo.ci_id"} selected {/eq}>{$vo.ci_name}</option>
                                {/volist}
                            </select>
                        </div>
                        <div class="layui-inline" style="width: 100px;">
                            <select lay-filter="city" level="3" name="city" id="city">
                                <option value="0">选择城市</option>
                                {notempty name="city"}
                                    {volist name="city" id="vo"}
                                        <option value="{$vo.ci_id}" {eq name="Request.param.city" value="$vo.ci_id"} selected {/eq}>{$vo.ci_name}</option>
                                    {/volist}
                                {/notempty}
                            </select>
                        </div>
                        <div class="layui-inline" style="width: 100px;">
                            <select lay-filter="town" name="town" id="town">
                                <option value="0">选择区县</option>
                                {notempty name="town"}
                                    {volist name="town" id="vo"}
                                        <option value="{$vo.ci_id}" {eq name="Request.param.town" value="$vo.ci_id"} selected {/eq}>{$vo.ci_name}</option>
                                    {/volist}
                                {/notempty}
                            </select>
                        </div>
                        <div class="layui-inline" style="width: 80px;">
                            <select name="status" id="status">
                                <option value="">状态</option>
                                <option value="1" {eq name="Request.param.status" value="1"} selected {/eq}>启用</option>
                                <option value="0" {eq name="Request.param.status" value="0"} selected {/eq}>禁用</option>
                            </select>
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <button class="layui-btn"  lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i>搜索</button>
                            <a href="{:url('Admin/adminList')}">
                                <button type="button" class="layui-btn"><i class="layui-icon">&#xe639;</i>清空</button>
                            </a>
                        </div>
                    </form>
                </div>
                <div class="layui-card-header">
                    {eq name="check.AdminadminAdd" value="1"}
                        <button class="layui-btn" onclick="common.openWindow('新增管理员','{:url('Admin/adminAdd')}','500')">
                            <i class="layui-icon">&#xe654;</i>新增管理员
                        </button>
                    {/eq}
                    {eq name="check.AdminadminDelAll" value="1"}
                        <button class="layui-btn layui-btn-danger" onclick="dataDelAll()">
                            <i class="layui-icon">&#xe640;</i>批量删除
                        </button>
                    {/eq}
                </div>
                <div class="layui-card-body layui-table-body">
                    <table class="layui-table layui-form">
                        <thead>
                        <tr>
                            <th width="10">
                                <input type="checkbox" lay-filter="checkbox" name="id" value="" lay-skin="primary">
                            </th>
                            <th width="40">头像</th>
                            <th>姓名</th>
                            <th>角色</th>
                            <th>省市县</th>
                            <th>联系方式</th>
                            <th>状态</th>
                            <th>操作</th>
                        </thead>
                        <tbody>
                            {volist name="info" id="vo"}
                                <tr>
                                    <td>
                                        <input type="checkbox" name="id[]" value="{$vo.ad_id}" lay-skin="primary">
                                    </td>
                                    <td>
                                        {empty name="vo.ad_headerImg"}
                                            <a href="__static__/images/defaultHeader.png" target="_blank">
                                                <img src="__static__/images/defaultHeader.png" width="40" height="40">
                                            </a>
                                        {else/}
                                            <a href="__upload__/{$vo.ad_headerImg}" target="_blank">
                                                <img src="__upload__/{$vo.ad_headerImg}" width="40" height="40">
                                            </a>
                                        {/empty}
                                    </td>
                                    <td>{$vo.ad_name}</td>
                                    <td>{$vo.ag_name}</td>
                                    <td>{$vo.cityInfo.province} {$vo.cityInfo.city} {$vo.cityInfo.town}</td>
                                    <td>{$vo.ad_phone}</td>
                                    <td>
                                        {eq name="vo.ad_status" value="1"}
                                            <span class="layui-badge layui-bg-green">启用</span>
                                        {else/}
                                            <span class="layui-badge">禁用</span>
                                        {/eq}
                                    </td>
                                    <td class="td-manage">
                                        {eq name="check.AdminadminEdit" value="1"}
                                            <a href="javascript:;" onclick="common.openWindow('编辑权限','{:url('Admin/adminEdit',['id'=>$vo.ad_id])}','500')" >
                                                <i class="layui-icon">&#xe642;</i>编辑
                                            </a>
                                        {/eq}
                                        {eq name="check.AdminadminDel" value="1"}
                                            <a href="javascript:;" onclick="dataDel(this,'{$vo.ad_id}')" >
                                                <i class="layui-icon">&#xe640;</i>删除
                                            </a>
                                        {/eq}
                                    </td>
                                </tr>
                            {/volist}
                        </tbody>
                    </table>
                </div>
                <div class="layui-card-body ">
                    <div class="page">
                        {$info|raw}
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script>
    /**全选*/
    common.selectCheckbox('checkbox','id[]');
    /**加载城市*/
    common.getCity('province',"{:url('Index/getCityList')}");
    /**加载区县*/
    common.getCity('city',"{:url('Index/getCityList')}");
    /**树形组件获取分类列表*/
    const list = common.getTreeMenuList("{:url('Admin/getChildAuthGroupList')}");
    const info = {name:"role", className:".ele5", nodeClick:"data5", inputId:"#roleId"};
    common.treeMenu(list, info);
    /**删除*/
    function dataDel(obj, id){
        layer.confirm('确认要删除这条数据吗？',function(){
            var index = layer.load();
            //发异步删除数据
            $.ajax({
               type:"post",
               url:"{:url('Admin/adminDel')}",
               data:{id:id},
               dataType:'json',
               success:function (data) {
                   if(data.status === 1){
                       $(obj).parents("tr").remove();
                       layer.msg(data.info, {icon: 6,time:1500});
                   }else{
                       layer.msg(data.info, {icon: 5,time:1500});
                   }
                   layer.close(index);

               },
               error:function (data) {
                   console.log(data);
                   layer.msg("不好意思，出现了一点问题", {icon: 5});
               }
            });
        });
    }
    /**批量删除*/
    function dataDelAll() {
        //获取checkbox值
        var ids = common.getCheckboxVal();
        if(ids.length < 1){
            layer.msg('请选择需要操作的数据！',{time:1500, icon:5});
            return false;
        }
        layer.confirm('确认要删除选中的数据吗？',function(){
            var index = layer.load();
            $.ajax({
                type: 'POST',
                url: "{:url('Admin/adminDelAll')}",
                data: {ids:ids},
                dataType:'json',
                success:function(data){
                    if(data.status === 1){
                        layer.msg(data.info,{time:1500, icon:6},function(){
                            window.location.reload();
                        });
                    }else{
                        layer.msg(data.info,{time:1500, icon:5});
                    }
                    layer.close(index);

                },
                error:function(){
                    console.log(data.msg);
                    layer.msg("不好意思，出现了一点问题", {icon: 5});
                }
            });
        });
    }
</script>
</html>